//
// $Id: BezelView.m 6 2010-08-05 19:43:27Z principiadriver $
//
// Written by
//  Michael Klein <michael.klein@puffin.lb.shuttle.de>
//
// This file is part of Alternate Moves.
//
// This  is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#import "BezelView.h"
#import <ApplicationServices/ApplicationServices.h>

// 10.4 compatibility
@interface NSBezierPath (RoundedRect)
+ (NSBezierPath*)bezierPathWithRoundedRect:(NSRect)rect xRadius:(float)xr yRadius:(float)yr;
@end

@implementation BezelView

- (void)initWithFrame:(NSRect)frame
{
    if ((self = [super initWithFrame:frame]) != nil) {
        _backgroundColor = nil;
        _borderColor     = nil;
    }
}


- (void)dealloc
{
    [_backgroundColor release];
    [_borderColor     release];
    [super dealloc];
}


- (void)drawRect:(NSRect)dirtyRect
{
    NSBezierPath * border;
    if ([NSBezierPath respondsToSelector:@selector(bezierPathWithRoundedRect:xRadius:yRadius:)]) {
        border = [NSBezierPath bezierPathWithRoundedRect:[self bounds] xRadius:10.0 yRadius:10.0];
    } else {
        border = [NSBezierPath bezierPathWithRect:[self bounds]];
    }

    if (_backgroundColor) {
        [_backgroundColor setFill];
        [border fill];
    }
    if (_borderColor) {
        [_borderColor setStroke];
        [border stroke];
    }
    /*
     [[NSColor blackColor] setStroke];
     [border setLineWidth:2.0];
     */
}


- (NSColor*)backgroundColor
{
    return _backgroundColor;
}


- (void)setBackgroundColor:(NSColor*)color
{
    [color retain];
    [_backgroundColor release]; 
    _backgroundColor = color;
    [self setNeedsDisplay:YES];
}


- (NSColor*)borderColor
{
    return _borderColor;
}


- (void)setBorderColor:(NSColor*)color
{
    [color retain];
    [_borderColor release]; 
    _borderColor = color;
    [self setNeedsDisplay:YES];
}

@end
